package com.cl.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;

public class PhotoUrlTag extends TagSupport{

	private static final long serialVersionUID = 4512241072079966773L;
	private String url;
	
	@Override
	public int doEndTag() throws JspException {
		try {
			if(StringUtils.isBlank(url)){
				HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
				String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
				url = basePath+"img/defHead.png";
			}
			JspWriter writer = pageContext.getOut();
			writer.print(url);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
}
